package com.example.ssm.enums;

import com.example.ssm.strategy.PaymentStrategy;

/**
 * 支付方式枚举类
 * 结合策略模式，每个枚举值对应一个支付策略的bean名称
 */
public enum PaymentType {

    ALIPAY("alipay", "支付宝支付", "alipayStrategy"),
    WECHAT("wechat", "微信支付", "wechatPayStrategy"),
    BANK_CARD("bankCard", "银行卡支付", "bankCardStrategy");

    private final String code;
    private final String desc;
    private final String strategyBeanName; // 策略的Spring bean名称

    PaymentType(String code, String desc, String strategyBeanName) {
        this.code = code;
        this.desc = desc;
        this.strategyBeanName = strategyBeanName;
    }

    public String getCode() {
        return code;
    }

    public String getDesc() {
        return desc;
    }

    public String getStrategyBeanName() {
        return strategyBeanName;
    }

    /**
     * 根据支付方式代码获取对应的枚举值
     * @param code 支付方式代码
     * @return 支付方式枚举
     */
    public static PaymentType getByCode(String code) {
        if (code == null) {
            return null;
        }

        for (PaymentType type : PaymentType.values()) {
            if (type.getCode().equals(code)) {
                return type;
            }
        }

        return null;
    }
}
